package com.zhc.service.impl;

import com.github.pagehelper.PageHelper;
import com.zhc.dao.ProductMapper;
import com.zhc.pojo.Product;
import com.zhc.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductService implements IProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public Product getProductNyProductNameAndproductNum(Product product) {
        Product product1 = productMapper.getProductNyProductNameAndproductNum(product);
        return product1;
    }

    @Override
    public List<Product> getAllProducts(String productName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> allProducts = productMapper.getAllProducts(productName);
        return allProducts;
    }

    @Override
    public Product getProductById(Integer id) {
        Product product = productMapper.getProductById(id);
        return product;
    }

    @Override
    public int addProduct(Product product) {
        int i = productMapper.addProduct(product);
        return i;
    }

    @Override
    public int editProduct(Product product) {
        int i = productMapper.editProduct(product);
        return i;
    }

    @Override
    public int delById(Integer id) {
        int i = productMapper.delById(id);
        return i;
    }

    @Override
    public int delAll(List<Integer> ids) {
        int i = productMapper.delAll(ids);
        return i;
    }

    @Override
    public Product getProductByProductName(String productName) {
        Product product= productMapper.getProductByProductName(productName);
        return product;
    }
}
